package com.readboottest.chain.client;


import com.readboottest.entity.Book;
import com.readboottest.entity.BookCatalogue;
import com.readboottest.util.StringUtil;

import java.util.List;
import java.util.Scanner;


/**
 * @author zhanghuiyong
 * @创建时间 2019年05月31日
 * @描述: 新笔趣网小说检索
 **/

public abstract class SearchWebsite implements ISearchWebsite {

    /**
     * 小说阅读
     *
     * @param keyWord    书名
     * @param codeNumber 章节号
     * @是否通用 是
     */
    @Override
    public void readingNovel(String keyWord, Integer codeNumber) {
        //获取书籍
        Book novel = this.getNovel(keyWord);
        //获取章节目录
        List<BookCatalogue> catalogueList = novel.getCatalogueList();
        if (null == catalogueList || catalogueList.size() < 1) {
            return;
        }
        System.out.println("开始书籍阅读:" + novel.getBookName());
        for (BookCatalogue bookWscq : catalogueList) {
            if (codeNumber > bookWscq.getId()) {
                continue;
            }
            Scanner scanner = new Scanner(System.in);
            int nextInt = scanner.nextInt();
            if (1 == nextInt) {
                String content = this.getNovelContent(bookWscq).getChapterContent();
                String newContent = StringUtil.novelContentDeleteStr(content);
                System.out.println(newContent);
                System.out.println("========章号ID:" + bookWscq.getId() + "," + bookWscq.getTitle() + "结束=========");
            }
            if (0 == nextInt) {
                System.out.println("结束书籍阅读:" + novel.getBookName());
                return;
            }
        }
    }

    /**
     * 网站搜索接口
     *
     * @param keyWord 关键字（小说名称）
     * @return book 书籍实体
     */
    @Override
    public Book searchWebsite(String keyWord) {
        return null;
    }

    /**
     * 获取书籍目录
     *
     * @param book 书籍名称实体
     * @return book 书籍目录实体
     */
    @Override
    public Book getNovelCatalogueList(Book book) {
        return null;
    }

    /**
     * 完整书籍获取
     *
     * @param keyWord 小说名称
     * @return book 完整书籍
     */
    @Override
    public Book getNovel(String keyWord) {
        Book book = this.searchWebsite(keyWord);
        Book catalogueList = this.getNovelCatalogueList(book);
        return catalogueList;
    }

    /**
     * 获取章节内容
     *
     * @param bookCatalogue 章节实体
     * @return content 书籍内容
     */
    @Override
    public BookCatalogue getNovelContent(BookCatalogue bookCatalogue) {
        return null;
    }

    /**
     * 网站来源
     *
     * @return
     */
    public abstract String websiteType();

}
